#ifndef	__BFX_REF_XMLNODEMAP_H__
#define	__BFX_REF_XMLNODEMAP_H__

namespace BFX
{

//////////////////////////////////////////////////////////////////////////////

typedef	REFWrapper<Array<REF<REFXMLNode> > >	REFXMLNodeArray;
#ifdef	BFX_DLL_BUILD
template class BFX_API REF<REFXMLNodeArray>;
#endif

//////////////////////////////////////////////////////////////////////////////

// Represents a collection of nodes that can be accessed by name or index.
class BFX_API REFXMLNodeMap : public REFObject
{
	friend class REFXMLDocumentType;
	friend class REFXMLDocument;
public:
	virtual ~REFXMLNodeMap();

	// Retrieves a node specified by name.
	virtual REFXMLNode* GetNamedItem(const UniString& strName) const;
	// Retrieves a node specified by LocalName and NamespaceURI.
	virtual REFXMLNode* GetNamedItem(const UniString& strLocalName, const UniString& strNamespaceURI) const;
	// Adds a node using its Name property
	virtual REFXMLNode* SetNamedItem(REFXMLNode* pNode);
	// Removes the node specified by name.
	virtual REFXMLNode* RemoveNamedItem(const UniString& strName);
	// Removes a node specified by local name and namespace URI.
	virtual REFXMLNode* RemoveNamedItem(const UniString& strLocalName, const UniString& strNamespaceURI);

	// Gets the number of nodes in this collection.
	virtual int GetCount() const;
	// Retrieves the node at the specified index in this collection.
	virtual REFXMLNode* GetNode(int iIndex) const;

protected:
	REFXMLNodeMap(REFXMLNode* pParent);

	int FindNodeOffset(const UniString& strName) const;
	int FindNodeOffset(const UniString& strLocalName, const UniString& strNamespaceURI) const;
	REFXMLNode* ReplaceNodeAt(int i, REFXMLNode* pNode);
	virtual REFXMLNode* RemoveNodeAt(int i);
	virtual REFXMLNode* InsertNodeAt(int i, REFXMLNode* pNode);
	virtual REFXMLNode* AddNode(REFXMLNode* pNode);

protected:
	REFXMLNode*		m_pParent;
	REF<REFXMLNodeArray>	m_pNodes;
};

#ifdef	BFX_DLL_BUILD
template class BFX_API REF<REFXMLNodeMap>;
#endif

}	//	namespace BFX

#endif	//	__BFX_REF_XMLNODEMAP_H__
